home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / UTILITY / BANDOG.ARJ / ROT13.C < prev    next >
C/C++ Source or Header  |  1991-01-05  |  856b  |  44 lines

  1. #include <stdio.h>
  2.  
  3. main( int argc, char *argv[] )
  4. {
  5.     FILE *stream;
  6.     int i;
  7.  
  8.     /* Check for proper command line syntax */
  9.     if( argc == 1 ) {
  10.         puts( "Command syntax is:\n\nROT13 infile [> outfile]" );
  11.         exit( 1 );
  12.     }
  13.     else {
  14.         /* Open file for binary input */
  15.         if( ( stream = fopen( argv[1], "rb" ) ) == NULL ) {
  16.             puts( "Can't open file" );
  17.             exit( 1 );
  18.         }
  19.     }
  20.  
  21.     /* Encrypt/decrypt entire file */
  22.     while( !feof( stream ) ) {
  23.         i = fgetc( stream );
  24.  
  25.         /* Rotate letters A-M up */
  26.         if( ( i >= 'A' && i <= 'M' ) || ( i >= 'a' && i <= 'm' ) )
  27.             i += 13;
  28.         else {
  29.             /* Rotate letters N-Z down */
  30.             if( ( i >= 'N' && i <= 'Z' ) || ( i >= 'n' && i <= 'z' ) )
  31.                 i += 13;
  32.         }
  33.  
  34.         /* Print character */
  35.         putchar( i );
  36.     }
  37.  
  38.     /* Close file */
  39.     fclose( stream );
  40.  
  41.     /* Return to DOS with no error code */
  42.     exit( 0 );
  43. }
  44.